package com.itheima.exception;

import com.itheima.common.R;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

//全局异常处理器
@RestControllerAdvice
public class GlobalExceptionAdvice {

    //处理自定义的异常
    @ExceptionHandler(BusinessException.class)
    public R<String> handlerBusinessException(Exception exception) {
        //打印异常
        exception.printStackTrace();

        //返回错误
        return R.error(exception.getMessage());
    }

    //处理普通异常异常
    @ExceptionHandler(Exception.class)
    public R<String> handlerException(Exception exception) {
        //打印异常
        exception.printStackTrace();

        //返回错误
        return R.error("网络繁忙~~~");
    }
}